
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<c:choose>--%>
        <%--<c:when test="${type==0}"></c:when>--%>
        <%--<c:otherwise>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>--%>
        <%--</c:otherwise>--%>
        <%--</c:choose>--%>

    </div>
</script>


<script type="text/html" id="barDemo">
    <c:choose>
    <c:when test="${sessionScope.user.utype==1}">
        <h4 style="color: red">您是管理员.但是订单不能删</h4>
    </c:when>
    <c:otherwise>
        <h4 style="color: red">您无权对本贴进行操作</h4>
    </c:otherwise>
    </c:choose>

</script>


<script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){


        var table = layui.table;
        var pn ;//当前页
        var pc ;//当前页分几

        table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/BIllServlet.action?flag=findBillAll'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '订单数据'
            ,cols: [[
                {type: 'checkbox', fixed: 'l条数据eft'}
                ,{field:'bid', title:'编号',  fixed: 'left', unresize: true, sort: true,align:'center'}
                ,{field:'bname', title:'商品名称', edit: 'text'}
                ,{field:'bprice', title:'总价', edit: 'text'}
                ,{field:'bprovider', title:'供应商'}
                ,{field:'bdate', title:'订单创建时间', edit: 'text'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true,
            limit:3,
            request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageCount' //每页数据量的参数名，默认：limit
            }
            ,response: {
                statusName: 'code'
                ,msgName:'msg'
                ,countName: 'total' //数据总数的字段名称，默认：count
                ,dataName: 'data' //数据列表的字段名称，默认：data
            },done:function(res, curr, count){
                pc = res.pageCount; //得到当前页分几条数据
                pn = curr ;//得到当前页
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    //obj.del();//删除此条数数
                    $.post("${pageContext.request.contextPath}/BillServlet.action?flag=deleteById","bid="+data.pid,function(data){
                        console.log(pn);
                        console.log(pc);
                        if(data.flag){
                            alert("成功");
                            table.reload('test',{//重载表格
                                page:{
                                    curr:pn,
                                    count:pc
                                }
                            })
                        }else{
                            alert("失败");
                        }
                    },"json");
                    layer.close(index);
                });
            }
    });
            }})
    })

</script>
</body>
</html>

<script>
    var form;
    var layer;
    layui.use(['form', 'layedit', 'laydate'], function(){
        var laydate = layui.laydate;
        form = layui.form;
        layer = layui.layer;

        //日期
        laydate.render({
            elem:'#ubirth'
        });
    });
</script>